package com.example.coreshopapp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.coreshopapp.R;
import com.example.coreshopapp.bean.BillPayData;
import com.example.coreshopapp.bean.ClassBillData;

import java.util.ArrayList;
import java.util.List;

public class BillPayAdapter extends RecyclerView.Adapter<BillPayAdapter.ViewHolder> {

    private List<BillPayData> billPayList = new ArrayList<>();

    public BillPayAdapter(List<BillPayData> billPayList) {
        this.billPayList = billPayList;
    }
    public void updateBillPayAdapter(List<BillPayData> billPayList) {
        this.billPayList = billPayList;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public BillPayAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bill_pay, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull BillPayAdapter.ViewHolder holder, int position) {
        BillPayData item = billPayList.get(position);
        holder.timeTv.setText(item.getClassEndTime());
        holder.ncTv.setText(item.getSourceNcClassBillNo());
        holder.classBillNoTv.setText(item.getSourceClassBillNo());
        holder.ncStatusTv.setText(item.getNcStatusName());
        holder.personTv.setText(item.getSysUserName());
        holder.moneyTv.setText("￥" + item.getNccAmount());
        holder.billPayCode.setText(item.getClassBillNo());
        holder.entrynoTv.setText(position + 1 +".");
    }

    @Override
    public int getItemCount() {
        return billPayList.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        private TextView timeTv, ncTv,ncStatusTv,personTv,moneyTv,classBillNoTv,billPayCode,entrynoTv;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            timeTv = itemView.findViewById(R.id.tv_time);
            ncTv = itemView.findViewById(R.id.tv_nc);
            ncStatusTv = itemView.findViewById(R.id.tv_nc_status);
            personTv = itemView.findViewById(R.id.tv_place_person);
            moneyTv = itemView.findViewById(R.id.tv_money);
            classBillNoTv = itemView.findViewById(R.id.tv_classBillNo);
            billPayCode = itemView.findViewById(R.id.bill_pay_code);
            entrynoTv = itemView.findViewById(R.id.tv_entryno);
        }
    }
}
